import os
import requests

cwd = os.path.dirname(os.path.realpath(__file__))
cdn = 'https://cdnjs.cloudflare.com/ajax/libs/'
with open('assets.txt','r') as f:
    data = f.read()
for line in data.split():
    url = line.strip()
    if url:
        *folder_array, filename = url.replace(cdn,'').split('/')
        folder = os.path.join(cwd, '/'.join(folder_array))
        filename = os.path.join(folder, filename)
        os.makedirs(folder, exist_ok=True)

        print('Downloading {}'.format(url))
        r = requests.get(url)
        with open(filename, 'wb') as w:
            w.write(r.content)
